﻿using System;
using System.Collections.Generic;
using System.Linq;

using PortalIntranet.DatabaseComponents;
using PortalIntranet.DatabaseComponents.Administracao;

namespace PortalIntranet.BusinessComponents.Administracao
{
	public class PortletsBll
	{
		public static Portlet Obter(int id)
		{
			using (var contexto = new IntranetContexto())
			{
				return contexto.Portlets
					.Where(c => c.Id == id
						&& !c.Desativado
						&& !c.Excluido)
					.SingleOrDefault();
			}
		}

		public static List<Portlet> ListarPortlets(int tipolayout)
		{
			using (var contexto = new IntranetContexto())
			{
				return contexto.Portlets
					.Where(c => c.TipoLayoutId == tipolayout
						&& !c.Desativado
						&& !c.Excluido)
					.OrderBy(o => o.Linha).ThenBy(o => o.Ordem)
					.ToList();
			}
		}
	}
}
